;;; GNU Guix --- Functional package management for GNU
;;;
;;; Copyright © 2021, 2022 jgart <jgart@dismail.de>
;;; Copyright © 2022 ( <paren@disroot.org>
;;;
;;; This file is not part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (guixrus packages suckless)
  #:use-module (guix build utils)
  #:use-module (guix gexp)
  #:use-module (guix build-system cargo)
  #:use-module (guix build-system cmake)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system meson)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (guixrus patches suckless)
  #:use-module (gnu packages)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages fonts)
  #:use-module (gnu packages fontutils)
  #:use-module (gnu packages crates-io)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages image)
  #:use-module (gnu packages messaging)
  #:use-module (gnu packages ncurses)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages suckless)
  #:use-module (gnu packages xorg)
  #:use-module ((guixrus contributors) #:prefix contributor:))

(define-public st-guixrus
  (package
    (inherit st)
    (name "st-guixrus")
    (version (package-version st))
    (source
     (origin
       (method url-fetch)
       (uri (string-append "https://dl.suckless.org/st/st-" version ".tar.gz"))
       (patches
        (list
         st-scrollback
         st-scrollback-mouse
         st-scrollback-mouse-altscreen
         st-swapmouse
         st-undercurl))
       (sha256
        (base32 "19j66fhckihbg30ypngvqc9bcva47mp379ch5vinasjdxgn3qbfl"))))
    (synopsis "GuixRUs fork of Suckless Terminal")))

(define-public dwm-with-windows-key
  (package
    (inherit dwm)
    (name "dwm-with-windows-key")
    (arguments
      (substitute-keyword-arguments (package-arguments dwm)
        ((#:phases phases)
         `(modify-phases ,phases
            (add-before 'build 'configure-modifier-key
              ;; https://dwm.suckless.org/customisation/windows_key/
              (lambda _
                (substitute* "config.def.h"
                  (("Mod1Mask") "Mod4Mask"))))
            (add-after 'install 'save-config-in-store
              (lambda* (#:key outputs #:allow-other-keys)
                (let ((out (assoc-ref outputs "out")))
                  (mkdir-p (string-append out "/include/dwm"))
                  (copy-file "config.h"
                             (string-append out "/include/dwm/config.h")))))))))
     (synopsis "Dwm with window key as modifier instead of alt key")))

(define-public st-blax
  (let ((commit "3ab2acb97a95d7608aec030af836c9d3ad713720")
        (revision "0"))
    (package
      (inherit st)
      (name "st-blax")
      (source
        (origin
          (method git-fetch)
          (uri (git-reference
            (url "https://github.com/blaxpot/blax-st.git")
            (commit commit)))
          (sha256
            (base32 "1qc7wajz90zgys3p7dfp881wi8rla0q2bk4ycrv81x01y5lc8h5f"))))
      (home-page "https://github.com/blaxpot/blax-st.git"))))

(define-public st-skiqqy
  (let ((commit "18ead93d1c8e0964451fbdf39e0c1c838a252534")
        (revision "0"))
    (package
      (inherit st)
      (name "st-skiqqy")
      (version (package-version st))
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://git.sr.ht/~skiqqy/st")
           (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32 "06jjd0x1s6rvc0xncybwsb6dw1sna4f045snh6s94nwnq7fgy0r8"))))
      (arguments
       `(,@(package-arguments st)
         #:phases
         (modify-phases %standard-phases
           (delete 'configure)
           (add-before 'build 'change-to-src-directory
             (lambda _ (chdir "src") )))))
      (home-page "https://git.sr.ht/~skiqqy/st")
      (synopsis "Suckless st fork by skiqqy"))))

(define-public st-jole
  (let ((commit "835d5d3d4d0061bd10d6b6ac7cc037535790c3c5")
        (revision "0"))
    (package
      (inherit st)
      (name "st-jole")
      (version (package-version st))
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://git.sr.ht/~jole/st")
           (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32 "0g1riaq7qh03kglqgahmzi7c283aizhs9ga01gy7c7kg4hzqnd0a"))))
      (home-page "https://git.sr.ht/~jole/st")
      (synopsis "Suckless st fork by jole"))))

(define-public awm
  (let ((commit "9501928402c63816f210e4c124172eecb523d697")
        (revision "0"))
    (package
      (inherit dwm)
      (name "awm")
      (version (package-version dwm))
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://github.com/Alpt/awm")
           (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32 "1avdikdmhwnrfb6mkwxd5hp1b1vzpkz5qx84s5cck22m94d13ckv"))))
      (home-page "https://github.com/Alpt/awm/")
      (synopsis "alpt-wm - dynamic window manager"))))

(define-public dwm-hansung
  (let ((commit "7a69e99b027c5f374f144a9c6124c7c00759bc6a")
        (revision "0"))
    (package
      (inherit dwm)
      (name "dwm-hansung")
      (version (package-version dwm))
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://git.sr.ht/~hansung/dwm")
           (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32 "1ypf31z1szvilyza745imcjwxv6px6i7afchs5wxfz2vy6ckbm2j"))))
      (home-page "https://git.sr.ht/~hansung/dwm")
      (synopsis "Suckless dwm fork by hansung"))))

(define-public st-sife-ops
  (let ((commit "2f6e597ed871cff91c627850d03152cae5f45779")
        (revision "0"))
    (package
      (inherit st)
      (name "st-sife-ops")
      (version (package-version st))
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://github.com/Sife-ops/st")
           (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32 "009psvmc77v6hfa96wln0r8vlsi5y4nzs7iv9ws6f98wrdjgv5yh"))))
      (home-page "https://github.com/Sife-ops/st")
      (synopsis "Sife-ops fork of the Suckless Simple Terminal"))))

(define-public surf-sxmo
  (package
    (inherit surf)
    (name "surf-sxmo")
    (version "2.0.3")
    (source
     (origin
       (method git-fetch)
       (uri
        (git-reference
         (url "https://git.sr.ht/~mil/sxmo-surf")
         (commit version)))
       (file-name (git-file-name name version))
       (sha256
        (base32 "19q0cyp703gjcvj5yivwka94v9j24h1kbj6476m505xg3ircczgr"))))
    (home-page "https://git.sr.ht/~mil/sxmo-surf")
    (synopsis "The suckless surf browser fork for sxmo")
    (license license:expat)))

(define-public dmenu-sxmo
  (package
    (inherit dmenu)
    (name "dmenu-sxmo")
    (version "5.0.11")
    (source
     (origin
       (method git-fetch)
       (uri
        (git-reference
         (url "https://git.sr.ht/~mil/sxmo-dmenu")
         (commit version)))
       (file-name (git-file-name name version))
       (sha256
        (base32 "19lqdv0b4b76vblbarrbs46i19vxwpsjb6gmi7hcii62rzhm52kp"))))
    (home-page "https://git.sr.ht/~mil/sxmo-dmenu")
    (synopsis "Dmenu for sxmo")
    (description
"@code{dmenu-sxmo} works primarily by using volume/power keys for
selection along with some other patches.")
    (license license:expat)))

(define-public dwm-sxmo
  (package
    (inherit dwm)
    (name "dwm-sxmo")
    (version "6.2.15")
    (source
     (origin
       (method git-fetch)
       (uri
        (git-reference
         (url "https://git.sr.ht/~mil/sxmo-dwm")
         (commit version)))
       (file-name (git-file-name name version))
       (sha256
        (base32 "1laidsmdjgm95kh00hq2xdlvcc46jnpzvgzm82clz3m6c037d2i9"))))
    (home-page "https://git.sr.ht/~mil/sxmo-dwm")
    (synopsis "Dwm for sxmo - multikey, swallow, dock, among other patches")
    (license license:expat)))

(define-public st-ckyln
  (let ((commit "bdf70c237524129843f253ea0648c0cf112ac902")
        (revision "0"))
    (package
      (inherit st)
      (name "st-ckyln")
      (version "0.8.4.1")
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "git://git.ckyln.com/st")
           (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32 "14712q79mb5da3jgvikmn22rc7cv5f6fn653zd4pqxq92wvfpqiw"))))
      (home-page "https://git.ckyln.com/st/file/README.html")
      (synopsis "Cem Keylan's fork of the suckless simple terminal")
      (license license:expat))))

(define-public dmenu-ckyln
    (package
      (inherit dmenu)
      (name "dmenu-ckyln")
      (version "5.0-1")
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "git://git.ckyln.com/dmenu")
           (commit version)))
         (file-name (git-file-name name version))
         (sha256
          (base32 "0nshrfmxfiq8g3pbrzpzz288kgwy0v0fqr4ddn19sqdkxgv2rnzk"))))
      (home-page "https://git.ckyln.com/dmenu/file/README.html")
      (synopsis "Cem Keylan's fork of the simple surf browser")
      (license license:expat)))

(define-public dwm-ckyln
  (let ((commit "865a0d9227ce25ca37d3573c1babc59b52d9f510")
        (revision "0"))
    (package
      (inherit dwm)
      (name "dwm-ckyln")
      (version "1.3")
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "git://git.ckyln.com/dwm")
           (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32 "099as22p0lczq11mpiy6lbzdvxm7vkkcl47lbbn9fg9s934c9hfn"))))
      (home-page "https://git.ckyln.com/dwm/file/README.html")
      (synopsis "Cem Keylan's build of dwm")
      (license license:expat))))

(define-public surf-a2n-s
  (let ((commit "5b812484edb0b0dc5f886b362dff3e8eeec931d6")
        (revision "1"))
    (package
      (inherit surf)
      (name "surf-a2n-s")
      (version "0.8.4")
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://github.com/a2n-s/surf")
           (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32 "1gm86zih2pa341f2j8pvdr7dlykydw7pyicdj75794p68ih9d1hn"))))
      (home-page "https://github.com/a2n-s/surf")
      (synopsis "Surf fork by a2n-s")
      (license license:expat))))

(define-public sowm
  (package
    (name "sowm")
    (version "1.6")
    (source
     (origin
       (method git-fetch)
       (uri
        (git-reference
         (url "https://github.com/dylanaraps/sowm")
         (commit version)))
       (file-name (git-file-name name version))
       (sha256
        (base32 "1y9rh9lh1xwfkk8ps2wjy3d4cxz5q6dq7ci387fdxwc9f2dywici"))))
    (build-system gnu-build-system)
    (arguments
     `(#:tests? #f ; There are no tests.
       #:make-flags
       (list (string-append "CC=" ,(cc-for-target))
             (string-append "PREFIX=" %output))
       #:phases
       (modify-phases %standard-phases
         (delete 'configure))))
    (inputs
      (list libx11))
    (home-page "https://github.com/dylanaraps/sowm")
    (synopsis "Itsy bitsy floating window manager")
    (description
"@command{sowm} is an itsy bitsy floating window manager in around 220
lines of code.")
    (license license:expat)))

(define-public dminiwm
  (let ((commit "94cfcda85e3e53948152a1b58a2ef8c1dca55ca6")
        (revision "0"))
    (package
      (name "dminiwm")
      (version commit)
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://github.com/moetunes/dminiwm")
           (commit version)))
         (file-name (git-file-name name version))
         (sha256
          (base32 "10c5v0p4434272b0ndppka058j9qw1wxhha3i0x8iy2psmkyln2r"))))
      (build-system gnu-build-system)
      (arguments
       `(#:tests? #f ; There are no tests.
         #:make-flags
         (list (string-append "CC=" ,(cc-for-target))
               (string-append "PREFIX=" %output))
         #:phases
         (modify-phases %standard-phases
           (delete 'configure)
             (add-before 'build 'rename-config.h.def
               (lambda* (#:key inputs #:allow-other-keys)
                 (rename-file "config.h.def" "config.h"))))))
      (inputs
        (list dmenu libx11)) ; TODO patch dmenu_run
      (home-page "https://github.com/moetunes/dminiwm")
      (synopsis "Minimal dynamic tiling window manager built from catwm")
      (description
"@command{dminiwm} is a minimal and lightweight dynamic tiling window
manager with the goal of staying under 1000 lines of code.")
      (license license:expat))))

(define-public tinywm
  (package
    (name "tinywm")
    (version "1.3")
    (source
     (origin
       (method url-fetch)
       (uri
         (string-append "http://incise.org/files/dev/tinywm-" version ".tgz"))
       (sha256
        (base32 "1n04f1z46lp9kzshcxmiaigp4jw2k3mqbs2hfay72gfrx34fkdji"))))
    (build-system gnu-build-system)
    (arguments
     `(#:tests? #f ; There are no tests.
       #:make-flags
       (list (string-append "CC=" ,(cc-for-target))
             (string-append "PREFIX=" %output))
       #:phases
       (modify-phases %standard-phases
         (delete 'configure)
         (replace 'install
           (lambda* (#:key inputs outputs #:allow-other-keys)
             (let* ((out (assoc-ref outputs "out"))
                    (bin (string-append out "/bin")))
               (install-file "tinywm" bin)))))))
    (inputs
      (list libx11))
    (home-page "http://incise.org/tinywm.html")
    (synopsis "Tiniest window manager")
    (description
"@command{tinywm} is an itsy bitsy floating window manager in around 220
lines of code.")
    (license license:public-domain)))

(define-public perp
    (package
      (name "perp")
      (version "2.07")
      (source
       (origin
         (method url-fetch)
         (uri
           (string-append "http://b0llix.net/perp/distfiles/perp-"
                          version ".tar.gz"))
         (sha256
          (base32 "05aq8xj9fpgs468dq6iqpkfixhzqm4xzj5l4lyrdh530q4qzw8hj"))))
      (build-system gnu-build-system)
      (arguments
       `(#:tests? #f ; todo
         #:make-flags ; fixme
         (list (string-append "CC=" ,(cc-for-target))
               (string-append "SBINDIR=" %output)
               (string-append "MANDIR=" %output))
         #:phases
         (modify-phases %standard-phases
           (delete 'configure))))
      (home-page "http://b0llix.net/perp/")
      (synopsis "Persistent process supervisor and service managment framework")
      (description
"@command{perp} provides a set of daemons and utilities to reliably start,
monitor, log, and control a collection of persistent processes.")
      (license license:bsd-3)))

(define-public st-jetbrains
  (package (inherit st)
    (name "st-jetbrains")
    (arguments
      (substitute-keyword-arguments (package-arguments st)
              ((#:phases phases)
               `(modify-phases ,phases
                  (add-before 'build 'patch-font
                    (lambda _
                      (substitute* "config.def.h"
                        (("Liberation Mono:pixelsize=12:antialias=true:autohint=true")
                          "JetBrains Mono:style=Bold:size=8"))))))))
    (inputs
     (modify-inputs (package-inputs st)
       (prepend font-jetbrains-mono)))
     (synopsis "Simple terminal with the nice JetBrains font.")))

(define-public st-hermit
  (package (inherit st)
    (name "st-hermit")
    (arguments
      (substitute-keyword-arguments (package-arguments st)
              ((#:phases phases)
               `(modify-phases ,phases
                  (add-before 'build 'patch-font
                    (lambda _
                      (substitute* "config.def.h"
                        (("Liberation Mono:pixelsize=12:antialias=true:autohint=true")
                          "hermit:pixelsize=16:antialias=true:autohint=true"))))))))
    (inputs
     (modify-inputs (package-inputs st)
       (prepend font-hermit)))
     (synopsis "Simple terminal with the Hermit font.")))

(define-public termbox2
  (let ((revision "0")
        (commit "d618d5f1e5a7d8a9a02c72fd48b20a7bbe27bebc"))
    (package
     (name "termbox2")
     (version (git-version "0.0.0" revision commit))
     (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/termbox/termbox2")
                    (commit commit)))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "1a5ifdidw8879b4jbf3v4w2cbjxfhssl5v38w6j02m9gl841ps6s"))))
     (build-system gnu-build-system)
     (arguments
      (list ;; Tests require PHP, xterm, and xvfb from xorg-server. That's
            ;; probably too many dependencies for a simple terminal rendering
            ;; library, so let's disable the tests.
            #:tests? #f
            #:make-flags #~(list (string-append "CC=" #$(cc-for-target))
                                 (string-append "AR=" #$(ar-for-target))
                                 (string-append "prefix=" #$output))
            #:phases
            #~(modify-phases %standard-phases
                (add-after 'unpack 'delete-nonexistent-terminfos
                  (lambda _
                    ;; There's no rxvt-unicode entry in our terminfo database.
                    (substitute* "codegen.sh"
                      (("rxvt-unicode") ""))))
                (delete 'configure)
                (add-before 'build 'regenerate-termbox-h
                  (lambda _
                    (setenv "TERM" "dumb")
                    (invoke "make" "terminfo")))
                (replace 'build
                  (lambda* (#:key make-flags #:allow-other-keys)
                    (apply invoke "make" "libtermbox.a" make-flags)
                    (apply invoke "make" "libtermbox.so" make-flags)))
                (add-after 'install 'install-libs
                  (lambda* (#:key outputs #:allow-other-keys)
                    ;; For some reason, `make install` only installs the header
                    ;; file.
                    (let* ((out (assoc-ref outputs "out"))
                           (libdir (string-append out "/lib")))
                      (install-file "libtermbox.a" libdir)
                      (install-file "libtermbox.so" libdir))))
                (add-after 'install 'install-pc-file
                  (lambda* (#:key outputs #:allow-other-keys)
                    ;; termbox2 doesn't provide a pkg-config file, so let's make
                    ;; one ourselves.
                    (let* ((out (assoc-ref outputs "out"))
                           (pc-dir (string-append out "/share/pkgconfig")))
                      (mkdir-p pc-dir)
                      (call-with-output-file
                       (string-append pc-dir "/termbox.pc")
                       (lambda (pc-file)
                         (display (string-append
                                   "prefix=" out "\n"
                                   "includedir=${prefix}/include\n"
                                   "libdir=${prefix}/lib\n"
                                   "\n"
                                   "Name: termbox2\n"
                                   "Description: Simple terminal rendering "
                                   "library\n"
                                   "Version: " #$version "\n"
                                   "Cflags: -I${includedir}\n"
                                   "Libs: -L${libdir} -ltermbox")
                                  pc-file)))))))))
     (native-inputs (list ;; ncurses' `infocmp` program is required to generate
                          ;; termbox.h... the irony is painful.
                          ncurses))
     (home-page "https://github.com/termbox/termbox2")
     (synopsis "Simple terminal rendering library")
     (description "The @code{termbox2} library provides a simple API for
constructing terminal user interfaces.")
     (license license:expat)
     (properties `((maintainers . (,contributor:unmatched-paren)))))))

(define-public miniz
  ;; Last release was on 27-06-2021; there have been many commits since
  ;; then.
  (let ((commit "be92575500f71dfb5ac7b0c5bb47b6e736c23039")
        (revision "0"))
    (package
     (name "miniz")
     (version (git-version "2.2.0" revision commit))
     (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/richgel999/miniz")
                    (commit commit)))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "0w42vagcv4b0hcf0jk7vamrcpmw62dblx9856j98msdfm3qv1xzi"))))
     (arguments
      (list #:configure-flags
            #~(list "-DBUILD_SHARED_LIBS=ON")
            ;; No test target.
            #:tests? #f))
     (build-system cmake-build-system)
     (home-page "https://github.com/richgel999/miniz")
     (synopsis "Simple replacement for @code{zlib}")
     (description
      "@code{miniz} is a simple, tiny replacement for the @code{zlib}
compression library.")
     (license license:expat)
     (properties `((maintainers . (,contributor:unmatched-paren)))))))
